home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-06 | 3.8 KB | 78 lines | [TEXT/GEOL] |
- Item 4273821 18-Jan-90 21:46
-
- From: D4384 US Voting Mach, Sarner, Calvin,PRT
-
- To: MACAPP.TECH$ MacApp Technical
-
- Sub: Persistent Objects
-
- TO: Compatriots MACAPP.TECH$
- FROM: Greg Colvin (link D4384)
-
- I think I have a solution (or at least a hack) to the persistent object
- problem. I coded it months ago as insurance against 7.0 not being available in
- time, but have not yet exercised the code, as everything fits in memory so far
- (and my client doesn't trust the whole idea anyway!). The recent discussion in
- the archives makes me worry that perhaps it isn't that simple.
-
- My idea is to keep a copy of the object on a file, and keep in memory only
- enough information to read in the object when necessary. To this end I have
- created two new classes. In simplified form they are:
-
- TFileObject= OBJECT(TObject)
- itsLock: TFileLock; { info for maintaining locks }
- PROCEDURE TFileObject.Delete; { Say goodnight, Dick. }
- FUNCTION TFileObject.GetBuff(VAR buff: Ptr): INTEGER; { get record dat
- FUNCTION TFileObject.PutBuff(VAR buff: Ptr): INTEGER; { put record dat
- PROCEDURE TFileObject.LockForRead; { ALWAYS CALL BEFORE READ !!! }
- PROCEDURE TFileObject.LockForWrite; { ALWAYS CALL BEFORE WRITE !!! }
- PROCEDURE TFileObject.Unlock; { ALWAYS CALL AFTER LOCK !!! }
- FUNCTION TFileObject.Clone: TObject; OVERRIDE;
- PROCEDURE TFileObject.Copy(source: TFileObject);
- PROCEDURE TFileObject.Init;
- END;
-
- TFileLock= OBJECT(TObject)
- itsObject: TFileObject; { locked object }
- fileOffset: LONGINT; { offset of object data in document file }
- dataSize, { size of object data in document file }
- readLock,
- writeLock: INTEGER;
- {... other fields and methods for counting locks, maintaining cache, etc. }
- PROCEDURE TFileLock.SwapIn; { get data from file into object}
- PROCEDURE TFileLock.SwapOut;{ put object data into file }
- PROCEDURE TFileLock.Delete; { delete this object from file }
- END;
-
- Since the ClassID for an object is stored as an integer at the head of the
- object (or at least it must be for the UMacApp source to work), and the ClassID
- should suffice to invoke class methods, I figure that all that needs to stay in
- memory is the ClassId and itsFileLock. When I need to use an object I call
- LockForRead or LockForWrite, which calls itsLock.SwapIn to increment a lock
- counter and get the object data into memory. When I not using the object I call
- Unlock, which decrements the lock counter. When the write lock counter
- decrements to 0 the object fields are written to memory, using the appropriate
- PutBuff method. When memory in the Zone for object caching is low, the Memory
- Manager invokes a growZone function that invokes SwapOut on the least recently
- used objects that have no locks on them. SwapOut copies the object fields to
- disk, using the appropriate PutBuff method, and uses ReAllocHandle to keep only
- the INHERITED TFileObject in memory (that is, a valid ClassId and a handle to
- itsFileLock). SwapIn can then use ReAllocHandle and the appropriate GetBuff
- method to read the object fields back into memory.
-
- I have noticed that the MacApp debugger dislikes this trick, as the dehydrated
- form of the object fails the IsObject test! Things seem OK as long as the
- debugger is turned off. All the above REQUIRES that the portion of the object
- that remains in memory is adequate to invoke its LockForRead and LockForWrite
- methods, and that the reconstituted object is in fact still a valid object. Is
- this true? Or is it not nice to fool Mother MacApp?
-
- Could someone tell me if I am badly off the track? I am not yet on the group
- address (any day now), so a direct link would be appreciated.
-
- Thanks,
-
- Greg Colvin
- D4384
-
-